s = input().split()
n = int(s[0])
k = int(s[1])
s = input().split()
a = [0 for i in range(0, 100000)]
for i in range(0, n):
	a[i] = int(s[i])
ans = 0
j = 0
for i in range(0, n):
	while j < n :
		if a[j] - a[i] <= k:
			j = j + 1
		else:
			break
	ans = ans + (j - i) - 1
print(ans)